/*
 * @Copyright: 2017 www.yyfax.com Inc. All rights reserved.
 */
package com.yyfax.pay.order.model.to.pay;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.NotBlank;

import com.yyfax.framework.model.Params;
import com.yyfax.framework.yyfax.enums.RspCodeEnum;
import com.yyfax.pay.common.exception.YYPayException;
import com.yyfax.pay.common.util.CommonIdUtils;

/**
 * 支付 直连请求参数
 * 
 * @author jiangmy
 * @date 2017-04-11 13:56:44
 * @since v1.0.0
 */
@SuppressWarnings("serial")
public class PayPurchaseDirectParams extends Params {
	// @NotBlank(message = "用户IP不能为空")
	// private String userIp; // 用户端请求IP
	@NotBlank(message = "商户号不能为空")
	private String merchantCode; // 商户编号
	// @NotBlank(message = "用户id不能为空")
	// private String userId; // 商户用户ID
	@NotBlank(message = "订单号不能为空")
	private String orderId; // 商户订单号

	private String serialNo; // 第三方订单号(流水号)
	// private Integer amount; // 金额
	private String phone; // 手机号
	@NotBlank(message = "token不能为空")
	private String token; // 支付令牌
	@NotBlank(message = "validCode不能为空")
	private String validCode; // 手机验证码

	// public String getUserIp() {
	// return userIp;
	// }
	//
	// public void setUserIp(String userIp) {
	// this.userIp = userIp;
	// }

	public String getMerchantCode() {
		return merchantCode;
	}

	public void setMerchantCode(String merchantCode) {
		this.merchantCode = merchantCode;
	}

	// public String getUserId() {
	// return userId;
	// }
	//
	// public void setUserId(String userId) {
	// this.userId = userId;
	// }

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public String getSerialNo() {
		return serialNo;
	}

	public void setSerialNo(String serialNo) {
		this.serialNo = serialNo;
	}

	// public Integer getAmount() {
	// return amount;
	// }
	//
	// public void setAmount(Integer amount) {
	// this.amount = amount;
	// }

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public String getValidCode() {
		return validCode;
	}

	public void setValidCode(String validCode) {
		this.validCode = validCode;
	}

	@Override
	public boolean validate() throws Exception {
		// if (StringUtils.isBlank(this.userIp)) {
		// throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'userIp'不能为空");
		// }
		//
		// if (StringUtils.isBlank(this.merchantCode)) {
		// throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'merchantCode'不能为空");
		// }
		//
		// if (StringUtils.isBlank(this.userId)) {
		// throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'userId'不能为空");
		// }
		//
		// if (StringUtils.isBlank(this.token)) {
		// throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'token'不能为空");
		// }
		//
		// if (StringUtils.isBlank(this.validCode)) {
		// throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'validCode'不能为空");
		// }

		if (StringUtils.isBlank(this.orderId) || this.orderId.length() > CommonIdUtils.PAY_ORDER_MAX_LENGTH) {
			throw new YYPayException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "orderId不能为空/长度不能超过" + CommonIdUtils.PAY_ORDER_MAX_LENGTH + "位",
					"订单号不能为空/长度不能超过" + CommonIdUtils.PAY_ORDER_MAX_LENGTH + "位");
		}

		// if (this.amount <= 0) {
		// throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'amount' 不能小于等于 0 分");
		// }

		return true;
	}

	// @Override
	// public String[] signFields() {
	// return new String[] { "userIp", "merchantCode", "userId", "orderId", "serialNo", "amount", "phone", "token", "validCode" };
	// }
}
